package br.com.vacine;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.ExpandableListView;
import br.com.vacine.Entity.VacinaEntity;
import br.com.vacine.dao.DB;
import br.com.vacine.util.Adapter;

public class InformativoActivity extends ActionBarActivity{

	private int gambiarra = 0;
	private List<String> nome = new ArrayList<String>();
	private List<String> descrcao = new ArrayList<String>();
	private List<VacinaEntity> lista = null;
	private ExpandableListView acordion;
	
	
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.informativos);

        carregarDados();
	}
	
	@Override
	public void onResume(){
		super.onRestart();
		carregarDados();
	}
	
	public void carregarDados(){

		DB db = new DB(this); 
		lista = db.listVacinaInformativos();
		
		for (int i = 0; i < lista.size(); i++) {
			String vacina = lista.get(i).getNomeVacina();
			String desc = lista.get(i).getDescricao(); 
			nome.add(vacina);
			descrcao.add(desc);
		}
		
		acordion = (ExpandableListView)findViewById(R.id.expandableListView1);
		acordion.setAdapter(new Adapter(this, nome, descrcao));
		
		if (gambiarra == 0) {

			lista.clear();
			nome.clear();
			descrcao.clear();
			gambiarra = 1;
		}
	}

	public void cadastrarVacina(View v){
		
		Intent it = new Intent(this, CadastroVacinaActivity.class);
		startActivity(it);
		
	}
	
}
